package org.framework.define.bean.entity.converter;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.thoughtworks.xstream.converters.SingleValueConverter;

public class DateTimeConverter implements SingleValueConverter { 
    
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

	@SuppressWarnings("rawtypes")
	@Override
	public boolean canConvert(Class paramClass) {
		return paramClass.equals(Date.class) || paramClass.equals(Timestamp.class);
	}

	@Override
	public String toString(Object paramObject) {
		if(paramObject !=null)
			return format.format(paramObject);
		return "null";
	}

	@Override
	public Object fromString(String paramString) {
		
		try {
			return format.parseObject(paramString);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	} 
 
} 